package com.augurit.wf.mgmt.convert;

import java.util.ArrayList;
import java.util.List;

import org.jbpm.api.task.Task;

import com.augurit.wf.common.entity.Jbpm4Task;
import com.augurit.wf.common.form.jbpm.Jbpm4TaskForm;

public class Jbpm4TaskConvertor {
	
	
	public static Jbpm4TaskForm convertToForm(Jbpm4Task entity){
		Jbpm4TaskForm form = null;
		if(entity != null){
			form = new Jbpm4TaskForm();
			
			form.setTaskInstDbid(entity.getTaskInstDbid());
			form.setAgent(entity.getAgent());
			form.setAgentName(entity.getAgentName());
			form.setAgentStartDate(entity.getAgentStartDate());
			form.setAgentEndDate(entity.getAgentEndDate());
			form.setActivityName(entity.getActivityName());
			form.setActivityChineseName(entity.getActivityChineseName());
			form.setDuedate(entity.getDuedate());
			form.setSignTime(entity.getSignTime());
			form.setCreate(entity.getCreate());
			form.setHandleComments(entity.getHandleComments());
			form.setHandleCommentsTime(entity.getHandleCommentsTime());
			form.setAssigneeName(entity.getAssigneeName());
			form.setAssignee(entity.getAssignee());
			form.setState(entity.getState());
		}
		return form;
	}
	
	public static List<Jbpm4TaskForm> convertToFormList(List<Jbpm4Task> entitys){
		List<Jbpm4TaskForm> forms = null;
		if(entitys != null){
			forms = new ArrayList<Jbpm4TaskForm>();
			for (Jbpm4Task entity : entitys) {
				Jbpm4TaskForm form = new Jbpm4TaskForm();
				
				form.setTaskInstDbid(entity.getTaskInstDbid());
				form.setAgent(entity.getAgent());
				form.setAgentName(entity.getAgentName());
				form.setAgentStartDate(entity.getAgentStartDate());
				form.setAgentEndDate(entity.getAgentEndDate());
				form.setActivityChineseName(entity.getActivityChineseName());
				form.setDuedate(entity.getDuedate());
				form.setSignTime(entity.getSignTime());
				form.setCreate(entity.getCreate());
				form.setHandleComments(entity.getHandleComments());
				form.setHandleCommentsTime(entity.getHandleCommentsTime());
				form.setAssigneeName(entity.getAssigneeName());
				form.setAssignee(entity.getAssignee());
				
				if(entity.getState() != null){
					if(Task.STATE_COMPLETED.equals(entity.getState()))
						form.setState("完成");
					if(Task.STATE_OPEN.equals(entity.getState()))
						form.setState("处理中");
					if(Task.STATE_SUSPENDED.equals(entity.getState()))
						form.setState("挂起");
				}
				
				forms.add(form);
			}
		}
		return forms;
	}
	
	public static void convertStateToChinese(List<Jbpm4Task> list){
		if(list != null && list.size()>0){
			for(Jbpm4Task task :list){
				if(task.getState() != null){
					if(Task.STATE_COMPLETED.equals(task.getState()))
						task.setState("完成");
					if(Task.STATE_OPEN.equals(task.getState()))
						task.setState("处理中");
					if(Task.STATE_SUSPENDED.equals(task.getState()))
						task.setState("挂起");
				}
			}
		}
	}
}
